package com.example.customview.gradienttext

import android.animation.ValueAnimator
import com.alibaba.android.arouter.facade.annotation.Route
import com.android.baselibrary.base.BaseFragment
import com.example.customview.R
import com.example.customview.arouter.CustomArouter
import com.example.customview.databinding.FragmentGradientBinding

/**
 * 仿歌词的textview
 */
@Route(path = CustomArouter.CUSTOM_GRADIENT_TEXT)
class GradientFragment :BaseFragment<FragmentGradientBinding>(){
    private var valueAnimator:ValueAnimator?=null
    override fun getLayoutID(): Int  = R.layout.fragment_gradient

    override fun initView() {
        valueAnimator = ValueAnimator.ofFloat(0.0f,1.0f)
        valueAnimator?.addUpdateListener {
            mBinding.gradientView.setProgress(it.animatedValue as Float)
        }
        valueAnimator?.duration = 2000
        valueAnimator?.repeatCount = ValueAnimator.INFINITE

        mBinding.btnStart.setOnClickListener {
            valueAnimator?.start()
        }
        mBinding.btnStop.setOnClickListener {
            valueAnimator?.end()
        }



    }
}